package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @description 供应商Controller层
 */
@RestController
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

   // 分页查询供应商
    @PostMapping("list")
    public Map<String,Object> list(Integer page,Integer rows,String supplierName){
       Map<String,Object> map = supplierService.list(page,rows,supplierName);
        return map;
    }

    //供应商添加或修改
    @PostMapping("save")
    public ServiceVO saveAndUpdate(Integer supplierId,Supplier supplier){
        supplierService.saveAndUpdate(supplierId,supplier);
        return new ServiceVO<>(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS,null);
    }


    //删除供应商（支持批量删除）
    @PostMapping("delete")
    public ServiceVO delete(String ids){
        supplierService.delete(ids);
        return new ServiceVO(SuccessCode.SUCCESS_CODE, SuccessCode.SUCCESS_MESS, null);
    }


}
